<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户修改个人信息页面</title>
    <script type="text/javascript" th:src="@{/js/jquery-3.2.1.min.js}"></script>
    <style type="text/css">
        #div1{
           /* border: 2px red solid;*/
            height: 300px;
            width: 600px;
            text-align: center;
            margin: 150px auto;
        }
        #div2{
            /*border: 1px palegreen solid;*/
            height: 200px;
            width: 400px;
            text-align: left;
            margin: auto;
        }
    </style>
    <script>
        $(function() {
            $.ajax({
                url: "/getPatient",
                type: "GET",
                data: {
                    "id": $("#hit").val()
                },
                dataType: "json",
                success: function (patient) {
                    show(patient);
                },
                error: function (patient) {
                    alert("患者查询失败！");
                }
            });
            function show(patient){
                /* var s = $('input[name="name"]').val()*/
                /*alert("name:"+s);*/
                $("#id").attr("value",patient.id);
                $("#name").attr("value",patient.name);
                $("#age").attr("value",patient.age);
                $("#phone").attr("value",patient.phone);
                $("#address").attr("value",patient.address);
                $("#medicalRecord").attr("value",patient.medicalRecord);
            }
        })
        $(function (){
            $("#button").one("click",function (){
                $.ajax({
                    url: "/modifyPatientById",
                    type: "POST",
                    /*此处的key名 <==> 实体类属性,使用数据库字段名出错*/
                    data: $('#form').serialize(),/*表单序列化*/
                    dataType: "json",
                    success(result){
                        alert("修改个人信息成功");
                        window.location.href="http://localhost:9090/lsy/profile";
                    },
                    error(result){
                        alert("修改个人信息失败");
                    }
                });

            });
        });
    </script>
</head>
<body>
<div id="div1">
    <div id="div2">
        <input id="hit" type="hidden" th:value="${id}">
        <h1>修改个人信息</h1>
        <form id="form">
            <input id="id" type="hidden" name="id" value=""><br>
            用户/患者姓名      <input id="name" type="text" name="name" value=""><br>
            用户/患者年龄      <input id="age" type="text" name="age" value=""><br>
            用户/患者电话      <input id="phone" type="text" name="phone" value=""><br>
            用户/患者地址      <input id="address" type="text" name="address" value=""><br>
            用户/患者过往病史   <input  id="medicalRecord" type="text" name="medicalRecord" value=""><br>
            <input type="button" name="button" id="button" value="修改">
            <input type="reset" value="重置"/>
            <a th:href="@{#}">返回</a>
        </form>
    </div>
</div>
</body>
</html>